package com.haoxiaozhang.hxz_app;

import android.text.TextUtils;

import com.haoxiaozhang.hxz_app.bean.User;
import com.haoxiaozhang.hxz_app.utils.SPUtils;

import org.w3c.dom.Text;

public class UserInfoHolder {
    private static UserInfoHolder mInstance = new UserInfoHolder();
    private static final String KEY_OUID = "key_ouid";
    private static final String KEY_OESID = "key_oesid";
    private User mUser;

    public static UserInfoHolder getInstance(){
        return mInstance;
    }

    public void setUser(User user){
        mUser = user;
        if(user!=null){
            SPUtils.getInstance().put(KEY_OUID,user.getOu_id());
            SPUtils.getInstance().put(KEY_OESID,user.getOes_id());
        }
    }

    public User getUser(){
        User u = mUser;
        if(u == null){
            String ouid = (String) SPUtils.getInstance().get(KEY_OUID,"");
            String oesid = (String) SPUtils.getInstance().get(KEY_OESID,"");
            if(!TextUtils.isEmpty(ouid) && !TextUtils.isEmpty(oesid)){
                u = new User();
                u.setOu_id(ouid);
                u.setOes_id(oesid);
            }
        }
        mUser = u;
        return mUser;
    }

    public void clearUser(){
        SPUtils.getInstance().clear();
    }
}
